﻿@using PMP.Models.ViewModel;
@{
    ViewBag.Title = "考试管理";
    Exam e = ViewBag.exam;
    List<Quest> listq = ViewBag.listq;
    List<ExamQuestRel> listr = ViewBag.listr;
}
<style>
    #tab1 th, #tab1 td {
        text-align: center;
    }

        #tab1 td.left {
            text-align: left;
        }

        #tab1 td.right {
            text-align: right;
        }
</style>

<div>
    <a href="@Url.Action("Manager")" class="layui-btn">返回考试管理</a>
</div>
<div>
    @e.Name
</div>
<div>
    <a class="layui-btn" href="@Url.Action("RelAdd",new { ID=e.ID})">增加题目</a>
    <a class="layui-btn" href="@Url.Action("RelDel",new { ID=e.ID})">移除题目</a>
    <a class="layui-btn" href="@Url.Action("RelSort",new { ID=e.ID})">题目排序</a>
</div>
<table id="tab1" class="layui-table">
    <thead>
        <tr>
            <th width="10%">序号</th>
            <th width="10%">ID</th>
            <th>题目</th>
            <th width="20%">操作</th>
        </tr>
    </thead>
    <tbody>
        @{
            int idx = 0;
        }
        @foreach (var r in listr)
        {
            idx++;
            Quest q = listq.Single(x => x.ID == r.QID);
            <tr rid="@r.ID" eid="@e.ID" qid="@q.ID">
                <td>@idx</td>
                <td>@q.ID</td>
                <td class="left">
                    @q.Title
                    <br />
                    @q.OptionA
                    <br />
                    @q.OptionB
                    <br />
                    @q.OptionC
                    <br />
                    @q.OptionD
                    <br />
                    答案： @q.Answer
                    <br />
                    @q.Analysis
                    <br />
                    @q.Point
                </td>
                <td><button class="layui-btn layui-btn-xs layui-btn-danger" onclick="remove(this);"><i class="layui-icon layui-icon-reduce-circle"></i>移除</button></td>
            </tr>
        }
    </tbody>
</table>
@section script{
    <script>

        function remove(ele) {
            let tr = $(ele).parent().parent();
            let obj = new Object();
            obj.ID = tr.attr("rid");
            obj.EID = tr.attr("eid");
            obj.QID = tr.attr("qid");
            layer.msg("正在保存，请稍候...", {
                icon: 16,
                time: 0,
                shade: 0.3,
                shadeClose: false
            });
            $.ajax({
                type: "POST",
                url: "@Url.Action("RemoveRel")",
                data: obj,
                success: function (result) {
                    tr.remove();
                    layer.msg(result.msg);
                },
                error: function (err) {
                    layer.msg(err.responseText);
                }
            });
        }
    </script>
}